FSI API: Mobile Devices
These methods are only available to apps running in mobile devices.
Checking for a mobile device
fsi.mobile.isMobile().
Use this method to test if the application is running in a mobile device, for example:
function takePhoto() {
if (fsi.mobile !== undefined && fsi.mobile.isMobile()) {
//Mobile device
<mobile code>
}
else {
// Desktop device
<desktop code>
}
}
Enabling a mobile device
fsi.mobile.enabled = <boolean>; Enables or disables mobile methods on a mobile device. Default is false, disabled.
fsi.mobile.isEnabled() <boolean>; Returns the mobile device status for mobile methods.
Taking a picture or selecting an image
fsi.mobile.takePhoto(<successCallBack>, <errorCallBack>, <options>); Takes a picture or selects an image from the mobile device's image library.
{Function} successCallBack, errorCallBack
{Object} options
Options
- quality: <number>. The quality of the saved image, expressed as a range of 0-100, where 100 is full resolution. Applies only to pictures taken with the device's camera application; not images selected from the image library.
- destinationType: <0>. The format of the image returned to the success callback. <0> defines DATA_URL which returns a base64 encoded string. Other values are not currently supported.
- correctOrientation: <boolean>. Rotates the image to correct for the orientation of the device during capture.
Pop-up menu
Calling fsi.mobile.takePhoto() displays a pop-up on the mobile, displaying options to:
- take a picture using the Camera. The device's default camera application is opened. After taking the picture, the camera application closes and the app is restored.
- select an image from the Gallery.
- Cancel the operation.
Example
This example:
- checks for a mobile device and enables it.
- takes a picture at 50% quality, or selects an image from the device's image library .
- creates an image file using the base64 data, string length, and a filename derived from the current date and time.
- renders the image in an Image Panel.
function takePhoto() {
if (fsi.mobile !== undefined && fsi.mobile.isMobile()) {
//Mobile device
var win = function setImagePanel(imgData) {
// save to image panel
var image = {};
image.Content = imgData;
image.FileName = new Date().getTime() + '.jpeg';
image.Length = imgData.length;
fsi.setById('imagepanel-NewImage', image);
};
var fail = function (e) {
};
var opt = {
quality: 50,
destinationType: 0,
correctOrientation: true
};
fsi.mobile.enabled = true;
fsi.mobile.takePhoto(win, fail, opt);
}
else {
// Desktop device
fsi.alert("Not available on a desktop computer");
}
}
See also FSI API: Image panel.
Get LocationType and LocationId (only works on iOS devices)
fsi.mobile.getLocationTypeAndId.
Use this method to return the type and id of a Location from a native container in a JSON format, for example:
function callGetLocationTypeAndId(){
fsi.mobile.getLocationTypeAndId (function(successResponseJSON){
alert(successResponseJSON);
});
}
JSON returned {"locationType":"", "locationId":""}